<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<script type="text/javascript">
    function checkForm() {
        var oldPassword=document.getElementById("oldPassword").value;
        var newPassword=document.getElementById("newPassword").value;
        var rPassword=document.getElementById("rPassword").value;
        $("#error").html("");
        if(oldPassword==""||newPassword==""||rPassword==""){
            document.getElementById("error").innerHTML="信息填写不完整！";
            return false;
        }else if(newPassword== oldPassword){
            document.getElementById("error").innerHTML="修改前后密码不能一致！";
            return false;
        }else if(newPassword!= rPassword){
            document.getElementById("error").innerHTML="密码的两次填写不一致！";
            return false;
        }
        if(onblurFn(oldPassword)){
            return false;
        }
        return true;
    }
</script>
<html>
<head>
    <title>修改密码</title>
    <%@ include file="/WEB-INF/common/header.jsp" %>
</head>
<script type="text/javascript">
    function onblurFn(oldPassword) {
        $("#error").html("");
        if(oldPassword!=null && oldPassword !=""){
            //校验用户输入的原密码是否正确
            $.ajax({
                type:"POST",
                url:"${ctx}/user/u_password?action=ajaxOldPassword",
                data:"oldPassword="+oldPassword,
                async:false,//同步请求
                success:function (msg) {
                    if (msg){
                        //用户输入的原密码不正确
                        $("#error").html(msg);
                        return true;
                    }else{
                        return false;
                    }
                }
            });
        }
    }
</script>

<body>
<div class="page-content d-flex align-items-stretch">
    <%@ include file="/WEB-INF/common/navbar.jsp" %>
    <%@ include file="/WEB-INF/common/menu.jsp" %>

    <!-- 内容主体区域 -->
    <div  class="content-inner" align="left">
        <h3 align="left" style="">修改密码</h3>
        <hr>
        <form action="${ctx}/user/u_password?action=change" method="post" onsubmit="return checkForm()">
            <div class="data_form">
                <table align="left" border="0">
                    <tr>
                        <td>原密码</td>
                        <td><input type="password" id="oldPassword" onblur="onblurFn(this.value)" name="oldPassword" ></td>
                    </tr>
                    <tr>
                        <td>新密码</td>
                        <td><input type="password" name="newPassword" id="newPassword"></td>
                    </tr>
                    <tr>
                        <td>确认密码</td>
                        <td><input type="password" name="rPassword" id="rPassword"></td>
                    </tr>
                    <tr>
                        <td align="center">
                            <input type="submit" value="提交" style="color: blue"></td>
                    </tr>
                    <div>
                        <font id="error" name="error" color="red">${error}</font>
                    </div>
                </table>
            </div>
        </form>
    </div>
</div>
<%@ include file="/WEB-INF/common/footer.jsp" %>
</body>
</html>
